package com.itcs.app.service.impl;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.itcs.app.service.PayTypeService;
import com.itcs.trading.mapper.UserAccountInfoMapper;
import com.itcs.trading.mapper.UserInfoMapper;
/**
 * 扣款方式操作
 * zhaojins 20171224
 * */
@Service
public class PayTypeServiceImpl implements PayTypeService{
@Autowired
 private UserInfoMapper userInfoMapper;
@Autowired
private UserAccountInfoMapper userAccountInfoMapper;
	@Override
	public Map<String, Object> updateMethod(Map<String, Object> paramMap) {
		// TODO Auto-generated method stub
		Map<String,Object> resMap=new HashMap<String,Object>();//返回结果信息
		int payMethod= (int) paramMap.get("payMethod");
		Map<String,Object> updateType=new HashMap<String,Object>();
		Map<String,Object> userAccountInfo =	userAccountInfoMapper.qryList((Long) paramMap.get("userId"));
		if(userAccountInfo==null){
			resMap.put("mess", "查不到对象，非法查询");
			resMap.put("state", "0");// 失败
		}else{
			BigDecimal accountBalance =(BigDecimal) userAccountInfo.get("account_balance");//获取账户余额
			if(1==payMethod){
				//判断账户余额，账户余额小于5，返回
				if(accountBalance.compareTo(new BigDecimal("5"))==-1){
					//提示余额不足，请尽快充值
				}
				updateType.put("payMethod", payMethod);
			}else if(0==payMethod){
				updateType.put("payMethod", payMethod);
			}else{
			//扣款方式，不是	0非自动扣款 1自动扣款，默认为1自动扣款
				updateType.put("payMethod", "1");
			}
			updateType.put("userId", paramMap.get("userId"));
			int ret=userInfoMapper.updaetPayType(updateType);
			if(ret==1){
				resMap.put("code", 200);
			}else{
				resMap.put("code", 300);
			}
		}
		return resMap;
	}

}
